package org.zjx.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;
import org.zjx.common.bean.Result;
import org.zjx.common.util.BeanUtil;
import org.zjx.dao.dto.PropDTO;
import org.zjx.dao.entity.Prop;
import org.zjx.service.IPropService;

import java.util.List;


@Tag(name = "道具管理接口")
@RestController
@RequestMapping("/prop")
@RequiredArgsConstructor
public class PropController {
    private final IPropService propService;

    @Operation(summary = "上传道具")
    @PostMapping("/saveProp")
    public Result saveProp(@RequestBody PropDTO propDTO) {
        Prop prop = BeanUtil.copyProperties(propDTO, Prop.class);
        prop.setCapabilities(propDTO.getFunction());
        propService.save(prop);
        return Result.isOk();
    }


    @SneakyThrows
    @Operation(summary = "匹配道具")
    @PostMapping("/identifyProp")
    public Result<List<Prop>> identifyProp(@RequestBody List<String> propStrings) {
        if (propStrings == null || propStrings.isEmpty()) {
            return Result.isFail(new Exception("上传数据为空"));
        }

        List<Prop> identifyProp = propService.identifyProp(propStrings);
        return Result.isOk().data(identifyProp);
    }

    @Operation(summary = "获取所有道具")
    @GetMapping("/selectAlProps")
    public Result<List<Prop>> selectAlProps() {
        List<Prop> props = propService.list();
        return Result.isOk().data(props);
    }
}
